﻿@model GaclibWebPage.Models.GettingStartPageModel

@{
    ViewBag.Title = "GacLib - Getting Started - Step 2";
}
<script type="text/javascript" src="@Url.Content("~/Content/SyntaxHighlighter/scripts/shCore.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/SyntaxHighlighter/scripts/shBrushCpp.js")"></script>
<link rel="Stylesheet" type="text/css" href="@Url.Content("~/Content/SyntaxHighlighter/styles/shCore.css")" />
<link rel="Stylesheet" type="text/css" href="@Url.Content("~/Content/SyntaxHighlighter/styles/shThemeRDark.css")" />
<tr>
    <td align="left" valign="top" colspan="6">
        <h1>Step 2. @Model.TutorialTitles[1]</h1>
        <p>
            The following code can be found in <strong>Libraries\GacUI\GacUIDemo\HelloWorld\HelloWorld.vcxproj</strong> if you <a href="@Url.Action("Download")">DOWNLOAD</a> the latest source code.
        </p>
        <p>
            Even a shortest GacUI program should contains 2 functions: <strong>WinMain</strong> and <strong>GuiMain</strong>. If you don't know how to write a WinMain function for a Windows program, please read <a href="http://msdn.microsoft.com/en-us/library/ms633559(v=vs.85)" target="_blank">this MSDN article</a>.
        </p>
        <h2>WinMain</h2>
        <p>
            The only function you need to call in WinMain is <strong>SetupWindowsDirect2DRenderer</strong> or <strong>SetupWindowsGDIRenderer</strong>. This is the only chance to choose which renderer to use after a program is executed. If you want to use Direct2D which is a good solution to speed up your program using GPU, call <strong>SetupWindowsDirect2DRenderer</strong>. If you want to use GDI, which is only suggested to use in an environment that Direct2D is not available, call <strong>SetupWindowsGDIRenderer</strong>.
        </p>
        <h2>GuiMain</h2>
        <p>
            The other function is <strong>GuiMain</strong>. A GuiMain function is required to be a GacUI program. When the GacUI finishes all the initializations, GuiMain function will be called, and you can use <strong>GetApplication()->Run </strong> to run a main window. GacUI supports multiple windows at the same time, but you should have a main window. GacUI will start to do finalization when the main window is closed.
        </p>
        <p>
            The following code shows how to write a hello world using GacUI.
        </p>
        <h2>Hello, world!</h2>
        <div class="CppCode">
            <pre class="brush: cpp; gutter: false;">
#include "..\..\Public\Source\GacUI.h"
#include &lt;Windows.h&gt;
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
{
    return SetupWindowsDirect2DRenderer();
}
void GuiMain()
{
    GuiWindow* window=g::NewWindow();
    window->SetText(L"Hello, world!");
    window->SetClientSize(Size(640, 480));
    window->MoveToScreenCenter();
    GuiControl* label=g::NewLabel();
    label->SetText(L"Welcome to GacUI Library!");
    {
        FontProperties font;
        font.fontFamily=L"Segoe UI";
        font.size=40;
        font.antialias=true;
        label->SetFont(font);
    }
    window->AddChild(label);
    GetApplication()->Run(window);
    delete window;
}
            </pre>
        </div>
        <h1>See also ...</h1>
        <ul>
            @for (int index = 0; index < Model.TutorialTitles.Length; index++)
            {
                <li>Step @(index + 1). <a href="@Url.Action("GettingStart_" + (index + 1).ToString(), "Home")">@Model.TutorialTitles[index]</a></li>
            }
        </ul>
    </td>
</tr>
<script type="text/javascript">
    SyntaxHighlighter.all()
</script>